package com.cloud.common.response;

import lombok.Data;

/**
 * @YIKOUJING
 * @author LXY
 * @Description 请求返回封装类
 * @createDate 2022/3/16
 * @createTime 22:52
 */
@Data
public class Result<T> {

    private String code;
    private Boolean status;
    private String message;
    private T data;

    public Result() {
    }

    public Result(T data) {
        this.code = CodeEnum.SUCCESS.getResultCode();
        this.status = true;
        this.message = CodeEnum.SUCCESS.getResultMsg();
        this.data = data;
    }

    /**
     * @YIKOUJING
     * @author LXY
     * @Description 成功
     * @createDate 2022/3/16
     * @createTime 22:53
     */
    public static <T>Result<T> success(T data){
        Result<T> suc = new Result<T>();
        suc.setCode("200");
        suc.setStatus(true);
        suc.setMessage("success");
        suc.setData(data);
        return suc;
    }

    /**
     * @YIKOUJING
     * @author LXY
     * @Description 失败
     * @createDate 2022/3/16
     * @createTime 22:53
     */
    public static <T>Result<T> error(T data, String code, String msg){
        Result<T> err = new Result<T>();
        err.setCode(code);
        err.setStatus(false);
        err.setMessage(msg);
        err.setData(data);
        return err;
    }

    /**
     * @YIKOUJING
     * @author LXY
     * @Description 失败
     * @createDate 2022/3/16
     * @createTime 22:53
     */
    public static <T>Result<T> error(String code, String msg){
        Result<T> err = new Result<T>();
        err.setCode(code);
        err.setStatus(false);
        err.setMessage(msg);
        return err;
    }
}
